import request from '@/utils/request'

export function listUser(pos, size, conditions) {
  return request({
    url: '/user/list',
    params: {
      'jsonCondition': JSON.stringify(conditions),
      'pos': pos,
      'size': size
    },
    method: 'get'
  })
}
export function getUser(uid) {
  return request({
    url: '/user/get',
    params: {
      'uid': uid
    },
    method: 'get'
  })
}
export function setUser(usermodel) {
  return request({
    url: '/user/set',
    data: usermodel,
    method: 'post'
  })
}

export function searchUser(keyword) {
  return request({
    url: '/user/searchbyname',
    params: {
      'name': keyword
    },
    method: 'get'
  })
}

export function delUser(usermodel) {
  return request({
    url: '/user/del',
    data: usermodel,
    method: 'post'
  })
}
export function delUsers(jsonUserModel) {
  return request({
    url: '/user/bulkdel',
    data: {
      data: jsonUserModel
    }, // contentType 要求接受JSON格式
    method: 'post'
  })
}

export function getLogin(uid) {
  // 该API不返回具体值，只返回是否存在登录信息
  return request({
    url: '/user/existlogininfo',
    params: {
      userId: uid
    },
    method: 'get'
  })
}

export function setPassword(loginmodel) {
  return request({
    url: '/user/changepassword',
    data: loginmodel,
    method: 'post'
  })
}
export function register(loginmodel, domain, role) {
  return request({
    url: '/user/register',
    data: {
      loginmodel: JSON.stringify(loginmodel),
      domain: domain,
      role: role
    },
    method: 'post'
  })
}
